using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Collections;
using FITHOU.DO;
using FITHOU.BL;

namespace FITHOU.FormDesign
{
    public partial class frHoiThoai : DevExpress.XtraEditors.XtraForm
    {
        int[] arr = new int[30];
        public static string listCH = "";
        private static string da = "";
        public frHoiThoai()
        {
            InitializeComponent();
        }

        private void frHoiThoai_Load(object sender, EventArgs e)
        {
            loadHT();
        }

        public int[] rdSNN(int total)
        {
            RandomNumber nbs = new RandomNumber();
            //const int Total = 30;
            ArrayList lstNumbers = nbs.RandomNumbers(total);

            for (int i = 0; i < lstNumbers.Count; i++)
                arr[i] = int.Parse(lstNumbers[i].ToString());

            return arr;
        }

        public void loadHT()
        {
            tbl_HoiThoaiDO obj = new tbl_HoiThoaiBL().SelectRandom();
            string s = obj.KichBan;
            da = obj.KichBan;
            string[] kban = s.Split('-');
            string kichban = "";
            int[] idKB = new int[10];
            int[] songaunhien = rdSNN(kban.Length);
            listHT.Items.Clear();
            for (int i = 0; i < kban.Length; i++)
            {
                
                int j = songaunhien[i];
                idKB[i] = int.Parse(kban[j-1]);
                //int tg = idKB[j];
                listHT.Items.Add(new tbl_TuDienBL().Select(idKB[i]).TA);
                //kichban += new tbl_TuDienBL().Select(idKB[i]).TA + "\n";
            }
            //int tes = 0;
            //tes = listHT.SelectedIndex;
            //if (tes == 0)
            //    btnUp.Visible = false;
            //else
            //    btnUp.Visible = true;
            //if (tes == listHT.ItemCount)
            //    btnDown.Visible = false;
            //else
            //    btnDown.Visible = true;
        }

        private void btnUp_Click(object sender, EventArgs e)
        {
            int i = 0;
            i = listHT.SelectedIndex;
            if (i != 0)
            {
                string s = listHT.SelectedValue.ToString();
                listHT.Items[i] = listHT.Items[i - 1];
                listHT.Items[i - 1] = s;
                listHT.SelectedIndex = i - 1;
            }
        }

        private void btnDown_Click(object sender, EventArgs e)
        {
            int i = 0;
            i = listHT.SelectedIndex;
            if (i != listHT.ItemCount-1)
            {
                string s = listHT.SelectedValue.ToString();
                listHT.Items[i] = listHT.Items[i + 1];
                listHT.Items[i + 1] = s;
                listHT.SelectedIndex = i + 1;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string list2;
            for (int i = 0; i < listHT.ItemCount; i++)
            {
                string s = listHT.Items[i].ToString();
                int s1 = new tbl_TuDienBL().SelectByTA(s).ID;
                listCH += s1.ToString() + "-";
                list2 = listCH;
            }
            tbl_HoiThoaiDO obj = new tbl_HoiThoaiDO();
            string kt = listCH.Substring(0, listCH.Length - 1);
            if (kt == da)
                MessageBox.Show("Chinh Xac");
            else
            {
                MessageBox.Show("Ban da lam sai");
                return;
            }
        }
    }
}